package com.jsoft.dao.impl;

import com.jsoft.dao.ContractInfoVoDao;
import com.jsoft.entiy.vo.ContractInfoVo;
import com.jsoft.util.DAOImpl;

/**
 * @program: CPM
 * @description:
 * @author: beibei
 * @create: 2022-09-08 21:01
 */
public class ContractInfoVoDaoImpl extends DAOImpl<ContractInfoVo> implements ContractInfoVoDao {
    @Override
    public ContractInfoVo getInfoVoById(Integer id) {
        ContractInfoVo contractInfoVo = null;
        String sql ="SELECT con.`id`,con.`type`,con.`startDate`,con.`endDate`,con.`money`,con.`payway`,con.`paystate`,cli.`c_name` `buyName`,\n" +
                "cli.`address` `buyAddress`,cli.`tel` `buyTel`,cli.`c_mail` `buyEmail`,cli.`url` `buyUrl`,emp.`name` `buyUser`,emp.`mobile` " +
                "`buyUserTel`,emp.`mail` `buyUserEmail`,t.c_name `sellName`,t.address `sellAddress`,t.tel `sellTel`,t.c_mail `sellEmail`," +
                "t.url `sellUrl`,t.name `sellUser`,t.mobile `sellUserTel`,t.mail `sellUserEmail`\n" +
                "FROM contract con \n" +
                "JOIN  employee emp ON con.`eId` = emp.`id`\n" +
                "JOIN  `client` cli ON emp.`id` = cli.`c_id`\n" +
                "JOIN (SELECT cli.`c_name`, con.`id`,cli.`address`,cli.`tel`,cli.`c_mail`,cli.`url`,emp.`name`,emp.`mobile`,emp.`mail`\n" +
                "FROM contract con \n" +
                "JOIN  `client` cli ON cli.`c_id` = con.`sellId`\n" +
                "JOIN  employee emp ON cli.`e_id` = emp.`id`) t ON con.`id` = t.id where con.`id` = ?;";

        try {
            contractInfoVo = get(sql, id);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return contractInfoVo;
    }

    @Override
    public ContractInfoVo getInfoVoByName(String name) {
        ContractInfoVo contractInfoVo = null;
        String sql ="SELECT con.`id`, cli.`c_name` `buyName`, cli.`address` `buyAddress`,cli.`tel` `buyTel`," +
                "cli.`c_mail` `buyEmail`,cli.`url` `buyUrl`," +
                "emp.`name` `buyUser`,emp.`mobile` `buyUserTel`,emp.`mail` `buyUserEmail`\n" +
                "FROM contract con \n" +
                "JOIN  `client` cli ON cli.`c_id` = con.`sellId`\n" +
                "JOIN  employee emp ON cli.`e_id` = emp.`id` where cli.`c_name` = ? LIMIT 1;";

        try {
            contractInfoVo = get(sql, name);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return contractInfoVo;
    }
}